#include "BodyMaker.h"


BodyMaker::BodyMaker()
{
}


BodyMaker::~BodyMaker()
{
}

b2Body* BodyMaker::makeCicle(b2World *_World, b2BodyType _Type, int _Radius, b2Vec2 pos)
{
	return BodyMaker::makeCicle(_World, _Type, _Radius,pos, NULL);
}

b2Body* BodyMaker::makeCicle(b2World *_World, b2BodyType _Type, int _Radius, b2Vec2 pos, void* _UserData)
{
	b2Body* body;
	b2BodyDef bodyDef;
	b2CircleShape circle;
	b2FixtureDef shapeDef;

	bodyDef.type = _Type;
	bodyDef.userData = _UserData;
	bodyDef.position.Set(pos.x / Define::PTM_RATIO, pos.y / Define::PTM_RATIO);
	body = _World->CreateBody(&bodyDef);

	// Create circle shape
	circle.m_radius = (float)_Radius / Define::PTM_RATIO;
	// Create shape definition and add to body
	shapeDef.shape = &circle;
	shapeDef.density = Define::BODY_DENSITY;
	shapeDef.friction = Define::BODY_FRICTION;
	shapeDef.restitution = Define::BODY_RESTITUTION;
	body->CreateFixture(&shapeDef);
	return body;
}

b2Body* BodyMaker::makeBox(b2World *_World, b2BodyType _Type, b2Vec2 _Size)
{
	return makeBox(_World, _Type, _Size, b2Vec2(0, 0), NULL);
}

b2Body* BodyMaker::makeBox(b2World *_World, b2BodyType _Type, b2Vec2 _Size, void* _UserData)
{
	return makeBox(_World, _Type, _Size, b2Vec2(0, 0), _UserData);
}

b2Body* BodyMaker::makeBox(b2World *_World, b2BodyType _Type, b2Vec2 _Size, b2Vec2 _Center)
{
	return BodyMaker::makeBox(_World, _Type, _Size, _Center, NULL);
}

b2Body* BodyMaker::makeBox(b2World *_World, b2BodyType _Type, b2Vec2 _Size, b2Vec2 _Center, void* _UserData)
{
	b2Body* body;
	b2BodyDef bodyDef;
	b2PolygonShape shapeDef;
	b2Fixture *fixture;


	bodyDef.type = _Type;
	bodyDef.userData = _UserData;
	body = _World->CreateBody(&bodyDef);

	shapeDef.SetAsBox((float)_Size.x/2 / Define::PTM_RATIO, (float)_Size.y/2 / Define::PTM_RATIO, b2Vec2((float)_Center.x / Define::PTM_RATIO, (float)_Center.y / Define::PTM_RATIO), 0);
	body->CreateFixture(&shapeDef, Define::BODY_DENSITY);
	fixture = body->GetFixtureList();
	fixture->SetRestitution(Define::BODY_RESTITUTION);
	body->ResetMassData();
	return body;
}
